$(function() {
    var module = {};
    var tools = Tools();
    var walletHT=tools.walletHT;

    module.init=function () {
        tools.getUserInfo();
        $('#pager').sjAjaxPager({
            url: accountURL+"wallet/trading_record",
            pageSize: 10,
            type :'GET',
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
            searchParam: {
                type : 1
            },
            beforeSend: function() {
            },
            success: function (data) {
                var content = data.data.data; 
                var list = '',
                    page = '';
                if(content && content.length){
                    list += $.map(content,function(value,len){
                        if(value.status=='0'){
                            var keystatus = '失败';
                        }else if(value.status=='1'){
                            var keystatus = '处理中';
                        }else if(value.status=='2'){
                            var keystatus = '成功';
                        }else if(value.status=='3'){
                            var keystatus = '失败';
                        }
                        //1 转入 2 转出 3 收益；  全部则不传
                        if(value.type=='1'){
                            //转入
                            if(value.payType=='1'){
                                var keyDesc = '银行卡';
                            }else if(value.payType=='2'){
                                var keyDesc = '余额';
                            }else if(value.payType=='3'){
                                var keyDesc = '';
                            }else if(value.payType=='4'){
                                var keyDesc = '定活宝';
                            }
                            var keyType = keyDesc+'转入';
                            if(value.status=='2'){
                                var instructions = '+'+value.amount+'元';
                                var proHtml = '<a target="_blank" href="'+walletHT+value.id+'">查看合同</a>'
                            }else{
                                var instructions = value.amount+'元';
                                var proHtml = '';
                            }
                            var  ostate = 'true';
                            var findTime  = value.finishedTime;
                        }

                        return '<tr><td>'+value.finishedTime+'</td><td>'+keyType+'</td><td>'+instructions+'</td><td>'+keystatus+'</td><td>'+proHtml+'</td></tr>';

                    }).join('')

                }else{
                    list += '<tr class="noList"><td colspan="5" align="center">暂无记录</tr>';
                }
                   
                $('.daily_oMain tbody').empty().append(list);

            },
            complete: function () {
            }
        });
        tools.doPost(accountURL+'wallet/info.do',{},module.wallinfo);
    };

    module.wallinfo=function (data){
        if(data.status==0){
            var content = data.data;

            var balance = content.balance.toFixed(3)+'';
            var balance_old = balance.substring(0,balance.length - 1);
            var yesterdayInterest = content.yesterdayInterest.toFixed(3)+'';
            var yesterdayInterest_old = yesterdayInterest.substring(0,yesterdayInterest.length - 1);

            var interest = content.interest.toFixed(3)+'';
            var interest_old = interest.substring(0,interest.length - 1);

            $('.money_num').html(balance_old);
            if(yesterdayInterest_old=='0.00'){
                $('#dayEarnings').html('暂无收益')
            }else{
                $('#dayEarnings').html(yesterdayInterest_old);
            }
            $('#allEarnings').html(interest_old);
        }else{
            window.location.href="https://www.qsdjf.com/login.html"
        }
    };

    module.init();
});